﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Esint.JudicialAuction.Model;
using Esint.JudicialAuction.Factory;
using Esint.JudicialAuction.IDAL;
using Esint.Common.Model;
using System.Linq;

namespace Esint.JudicialAuction.BLL
{
    /// <summary>
    /// 文件说明:  业务逻辑层
    /// 作    者: 谷明
    /// 生成日期: 2020年03月02日
    /// 模板版本: Esint.Template.BLL.BLL_01 版，适用于简单三层开发!
    /// 功能说明：
    /// </summary>
    public partial class Sys_CodeService
    {
        /// <summary>
        /// 功    能: 保存对象
        /// 说    明: 当主键为空时，新增操作
        ///           当主键不为空，根据主键进行修改
        /// <summary>
        public void Save(Sys_CodeInfo sys_Code)
        {
            if (String.IsNullOrEmpty(sys_Code.Flag) || String.IsNullOrEmpty(sys_Code.Code) )
            {
                 dataAccess.Insert(sys_Code);
            }
            else
            {
                 dataAccess.Update(sys_Code);
            }
        }

        /// <summary>
        /// 根据flag列表查询出对应的代码列表
        /// </summary>
        /// <param name="flagList"></param>
        /// <returns></returns>
        public List<Sys_CodeInfo[]> GetCodeListByFlagList(List<string> flagList)
        {
            List<Sys_CodeInfo[]> resList = new List<Sys_CodeInfo[]>();
            var codeList = dataAccess.GetCodeListByFlagList(flagList);

            for (int i = 0; i < flagList.Count; i++)
            {
                var flagItem = flagList[i];

                var qy = from t in codeList where t.Flag==flagItem select t;

                if (qy.FirstOrDefault() != null)
                {
                    resList.Add(qy.ToArray());
                }
                else
                {
                    resList.Add(new Sys_CodeInfo[0]);
                }
            }

            return resList;
        }

        public List<Sys_CodeInfo> GetCodeListByFlag(string flag)
        {
            List<string> flagList = new List<string>() { flag };

            var codeList = dataAccess.GetCodeListByFlagList(flagList);
            return codeList;
        }
    }
}
